<?php
// Configuration area start
// Please config the following settings before translation besides Traditional Chinese :)
// Notice :
// 1. Give rights to web server for writing all language files if you are not use M$ OS
// ex. /language/  and  /modules/*/language/
// 2. Please put this script to the root path of your SugarCRM installation

$bk = chr(10);     // The sign of line break
$qo = '  ';        // The sign for quote
$lang = 'zh_cn';   // Your language code in ISO-XXX
$encode = 'UTF-8'; // The encode you want to use

// Configuration area end
?>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="<?php echo $lang; ?>">

  <head>
	<meta http-equiv="Content-Type" content="text/html; charset=<?php echo $encode; ?>" />
	</head>
	<body>

<?php
$lang = "zh_cn";
if(!is_dir($lang)) {
	mkdir($lang);
}
$dir = "modules"; 
if ($dh = opendir($dir)) {
    while (($folder = readdir($dh)) !== false) { 
      if(is_dir($dir.'/'.$folder) && $folder!='..' && $folder!='.') {
        echo $folder.'<br/>';
        $lan_dir = $dir.'/'.$folder.'/language';
		if(is_dir($lan_dir)) {
		
			$dh2 = opendir($lan_dir);
			//while(($folder2 = readdir($dh2)) !== false) {
				//echo 'file:'.$folder2;//zh_cn.lang.php
			//}
			$fileName = $lan_dir.'/zh_cn.lang.php';
			if(is_file($fileName)) {
				$destDir = $lang.'/'.$dir.'/'.$folder.'/language';
				if(!is_dir($lang.'/'.$dir)) {
					mkdir($lang.'/'.$dir);					
				}
				if(!is_dir($lang.'/'.$dir.'/'.$folder)) {
					mkdir($lang.'/'.$dir.'/'.$folder);
				}
				if(!is_dir($lang.'/'.$dir.'/'.$folder.'/language')) {
					mkdir($lang.'/'.$dir.'/'.$folder.'/language');
				}				
					
				if(copy($fileName,$destDir.'/zh_cn.lang.php')) {
					echo 'copy successfully!<br>';
				} else {
					echo 'copy failed!<br>';
				}
			} else {
				echo "The lang file of the module does not exists!<br/>" ;
			}

			closedir($dh2);	
        } else {
			echo "The lang folder of the module does not exists!<br/>" ;
		}
      }
    } 
    closedir($dh);
	if(!is_dir($lang.'/include')) {
		mkdir($lang.'/include');
	}
	
	if(!is_dir($lang.'/include/language')) {
		mkdir($lang.'/include/language');
	}
	if(copy('include/language/zh_cn.lang.php',$lang.'/include/language/zh_cn.lang.php')) {
		echo 'include language files:copy successfully!<br>';
	} else {
		echo 'include language files:copy failed!<br>';
	}

} 
?>

</body>
</html>